module TipsUtils {

    //从下到上弹出
    export function showTipsDownToUp(str: string = "", textColor: number = GameGlobal.ins().TextColors.green, pos: egret.Point = undefined, timeMs: number = 1300): void {
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = pos ? pos.y : GameGlobal.ins().curHeight() / 2;
        effectTips.textColor = textColor;
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        effectTips.x = pos ? pos.x : GameGlobal.ins().curWidth() / 2 - effectTips.width / 2;
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;

        if (!SceneManager.instance.getStage().contains(effectTips)) {
            SceneManager.instance.getStage().addChild(effectTips);
        }

        var onComplete2: Function = function () {
            if (SceneManager.instance.getStage().contains(effectTips)) {
                SceneManager.instance.getStage().removeChild(effectTips);
                effectTips = null;
            }
        };
        var onComplete1: Function = function () {
            egret.Tween.get(effectTips).to({ alpha: 0 }, timeMs * 0.4).call(onComplete2, this);
        };
        effectTips.visible = true;
        egret.Tween.get(effectTips).to({ y: effectTips.y - 120, alpha: 1 }, timeMs * 0.6, egret.Ease.backOut).call(onComplete1, this);
    }

    //从左至右 或者 从右至左
    export function showTipsLeftOrRight(str: string = "", isWarning: boolean = false, isFromeLeft: boolean = true, pos: egret.Point = undefined): void {
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = pos ? pos.y : GameGlobal.ins().curHeight() / 2;
        if (isWarning) {
            effectTips.textColor = GameGlobal.ins().TextColors.red;
        } else {
            effectTips.textColor = GameGlobal.ins().TextColors.green;
        }
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        if (isFromeLeft) {
            effectTips.x = - effectTips.width;
        } else {
            effectTips.x = pos ? pos.x : GameGlobal.ins().curWidth();
        }
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;

        if (!SceneManager.instance.getStage().contains(effectTips)) {
            SceneManager.instance.getStage().addChild(effectTips);
        }

        if (isFromeLeft) {
            egret.Tween.get(effectTips).to({ x: GameGlobal.ins().curWidth() / 2 - effectTips.width / 2 - 50, alpha: 1 }, 300, egret.Ease.sineInOut);
        } else {
            egret.Tween.get(effectTips).to({ x: GameGlobal.ins().curWidth() / 2 - effectTips.width / 2 + 50, alpha: 1 }, 300, egret.Ease.sineInOut);
        }

        egret.setTimeout(function () {
            if (isFromeLeft) {
                egret.Tween.get(effectTips).to({ x: effectTips.x + 100 }, 500);
            } else {
                egret.Tween.get(effectTips).to({ x: effectTips.x - 100 }, 500);
            }
        }, this, 300);

        egret.setTimeout(function () {
            if (isFromeLeft) {
                egret.Tween.get(effectTips).to({ x: GameGlobal.ins().curWidth() }, 300, egret.Ease.sineIn);
            } else {
                egret.Tween.get(effectTips).to({ x: -effectTips.width }, 300, egret.Ease.sineIn);
            }
        }, this, 800);

        egret.setTimeout(function () {
            if (SceneManager.instance.getStage().contains(effectTips)) {
                SceneManager.instance.getStage().removeChild(effectTips);
                effectTips = null;
            }
        }, this, 1100);

    }

    //从里到外
    export function showTipsFromCenter(str: string = "", isWarning: boolean = false, pos: egret.Point = undefined): void {
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = pos ? pos.y : GameGlobal.ins().curHeight() / 2;
        if (isWarning) {
            effectTips.textColor = GameGlobal.ins().TextColors.red;
        } else {
            effectTips.textColor = GameGlobal.ins().TextColors.green;
        }
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        effectTips.x = pos ? pos.x : GameGlobal.ins().curWidth() / 2;
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;
        effectTips.anchorOffsetX = effectTips.width / 2;
        effectTips.anchorOffsetY = effectTips.height / 2;
        effectTips.scaleX = 0;
        effectTips.scaleY = 0;

        if (!SceneManager.instance.getStage().contains(effectTips)) {
            SceneManager.instance.getStage().addChild(effectTips);
        }

        var onComplete2: Function = function () {
            if (SceneManager.instance.getStage().contains(effectTips)) {
                SceneManager.instance.getStage().removeChild(effectTips);
                effectTips = null;
            }
        };
        egret.Tween.get(effectTips).to({ scaleX: 1, scaleY: 1, alpha: 1 }, 200);
        egret.setTimeout(function () {
            egret.Tween.get(effectTips).to({ alpha: 0 }, 500).call(onComplete2, this);
        }, this, 1000);

    }

    //从外到里
    export function showTipsBigToSmall(str: string = "", textColor: number = GameGlobal.ins().TextColors.green, pos: egret.Point = undefined): void {
        var effectTips = new egret.TextField();

        effectTips.size = 24;
        effectTips.y = pos ? pos.y : GameGlobal.ins().curHeight() / 2;
        effectTips.textColor = textColor;
        effectTips.alpha = 0;

        effectTips.text = str;
        effectTips.strokeColor = 0x000000;
        effectTips.x = pos ? pos.x : GameGlobal.ins().curWidth() / 2;
        effectTips.stroke = 2;
        effectTips.bold = true;
        effectTips.textAlign = egret.HorizontalAlign.CENTER;
        effectTips.anchorOffsetX = effectTips.width / 2;
        effectTips.anchorOffsetY = effectTips.height / 2;
        effectTips.scaleX = 4;
        effectTips.scaleY = 4;

        if (!SceneManager.instance.getStage().contains(effectTips)) {
            SceneManager.instance.getStage().addChild(effectTips);
        }

        var onComplete2: Function = function () {
            if (SceneManager.instance.getStage().contains(effectTips)) {
                SceneManager.instance.getStage().removeChild(effectTips);
                effectTips = null;
            }
        };
        egret.Tween.get(effectTips).to({ scaleX: 1, scaleY: 1, alpha: 1 }, 200);
        egret.setTimeout(function () {
            egret.Tween.get(effectTips).to({ alpha: 0 }, 500).call(onComplete2, this);
        }, this, 1000);

    }

}